package lwh.servlet.peoplemsg;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lwh.domain.PeopleMsg;
import lwh.service.PeopleMsgService;

public class GetPeopeDetailByPeopleCard extends HttpServlet {
	private PeopleMsgService service=new PeopleMsgService();
	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String peopleCard=new String(request.getParameter("peopleCard").getBytes("ISO8859-1"),"UTF-8");
		System.out.println(peopleCard);
		
		PeopleMsg p=service.getPeopleDetailByPeopleCard(peopleCard);
		StringBuilder builder=new StringBuilder();
		builder.append("[");
		builder.append("{");
		builder.append("pCard:\"").append(p.getpCard()).append("\",");
		builder.append("pName:\"").append(p.getpName()).append("\",");
		builder.append("pSex:\"").append(p.getpSex()).append("\",");
		builder.append("pBirthday:\"").append(p.getpBirthday()).append("\",");
		builder.append("pAge:").append(p.getpAge()).append(",");
		builder.append("pWorkAge:").append(p.getpWorkAge()).append(",");
		builder.append("pWorkType:\"").append(p.getpWorkType()).append("\",");
		builder.append("pNative:\"").append(p.getpNative()).append("\",");
		builder.append("pTelephone:\"").append(p.getpTelephone()).append("\",");
		builder.append("pCertificate:\"").append(p.getpCertificate()).append("\",");
		builder.append("pSkilled:\"").append(p.getpSkilled()).append("\",");
		builder.append("pCompany:\"").append(p.getpCompany()).append("\",");
		builder.append("pAddress:\"").append(p.getpAddress()).append("\"");
		builder.append("}");
		builder.append("]");
		request.setAttribute("json", builder.toString());
		request.getRequestDispatcher("/WEB-INF/page/departmentJson.jsp").forward(request,response);
	}

}
